package com.zhiyou100.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhiyou100.model.Tea;
import com.zhiyou100.service.TeaService;

@Controller
@RequestMapping("tea")
public class TeaController {
	@Resource
	TeaService teaService;

	@RequestMapping("show.do")
	public String show(Model model) {
		model.addAttribute("teas", teaService.queryAll());
		return "tea/show";
	}

	@RequestMapping("delete.do")
	public String delete(Integer id) {
		teaService.deleteById(id);
		return "redirect:show.do";
	}

	@RequestMapping("add.do")
	public String add() {

		return "tea/add";
	}

	@RequestMapping("insert.do")
	public String insert(Tea tea) {
		int ref = teaService.add(tea);
		System.out.println("打印是否添加" + ref+"++++++++"+tea);
		
		return "redirect:show.do";
	}

	@RequestMapping("edit.do")
	public String edit(Model model, Integer id) {
		model.addAttribute("tea", teaService.findById(id));
		return "tea/update";
	}

	@RequestMapping("update.do")
	public String update(Tea tea) {
		teaService.update(tea);
		return "redirect:show.do";
	}

	@RequestMapping("search.do")
	public String search(Tea tea, Model model) {
		// model.addAttribute("name", name);
		// 根据名字查询
		model.addAttribute("teas", teaService.findByTea(tea));

		return "tea/show";
	}

	// 根据日期查询
	@RequestMapping("time.do")
	public String time(String begin, String end, Model model) {
		model.addAttribute("teas", teaService.findByTime(begin, end));
		return "tea/show";
	}

	// 根据名字 性别 日期查询
	@RequestMapping("all.do")
	public String all(Tea tea, String begin, String end, Model model) {
		model.addAttribute("teas", teaService.findByAll(tea, begin, end));
		return "tea/show";
	}
	//向上移动
	@RequestMapping("up.do")
	public String up(Integer id) {
		teaService.findUpIndex(id);
		return "redirect:show.do";
	}
	
	
	//向下移动
		@RequestMapping("down.do")
		public String down(Integer id) {
			teaService.findDownIndex(id);
			return "redirect:show.do";
		}
}
